<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of LoginDAO
 *
 * @author emmanuelm
 */
class LoginDAO {
    private $dsn = "mysql:host=localhost;port=3306;dbname=aet_teste";
    private $user = "root";
    private $senha = "";
    
    public function getDsn() {
        return $this->dsn;
    }

    public function getUser() {
        return $this->user;
    }

    public function getSenha() {
        return $this->senha;
    }

       
        public function Login(Login $login){
        try{
            $con = new PDO($this->getDsn(), $this->getUser(), $this->getSenha());
            $con-> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $con-> exec("set names utf8");
            
            $sql = "SELECT * FROM empresa WHERE emp_email=? AND emp_senha=?";
            $st = $con->prepare($sql);
            $st-> bindValue(1,$login->getUser());
            $st-> bindValue(2,$login->getPass());
            $st-> execute();
            
            $linha = $st->rowCount();
            if ($linha<=0)
                throw  new Exception ("Login ou senha invalido");            
            
            else
                return $login;
        }
        
        catch (Exception $e){
            return $e->getMessage();
        }
        
        }
        function __construct() {
            
        }

}

?>
